﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iL = iLangl.Model;
using LWAPI = iLangl.LanguageWire.LanguageWireAPI;
using iLangl.Model;
using iLangl.LanguageWire.LanguageWireAPI;

namespace iLangl.LanguageWire.DAL.LanguageWireDAL.RealStorage
{
	public class SettingsDALLW : BaseStorageLWAPI, ISettingsDAL
	{
		public IList<iL.WorkArea> ReadWorkAreas()
		{
			StartSession();

			//READ WORK AREAS
			GetWorkAreaListRequest workAreasRequest = new GetWorkAreaListRequest();
			SubscribeRequest(workAreasRequest);
			GetWorkAreaListResponse workareas = service.GetWorkAreaList(workAreasRequest);
			//Log errors if any
			LogResponse(workareas);

			IList<iL.WorkArea> tpworkareas = new List<iL.WorkArea>();

			foreach (LWAPI.WorkArea area in workareas.WorkAreas)
			{
				iL.WorkArea tpworkarea = new iL.WorkArea();
				tpworkarea.Id = area.WorkAreaId.ToString();
				tpworkarea.Name = area.WorkAreaName;
				tpworkarea.ParentId = area.PrimaryWorkAreaId.ToString();

				tpworkareas.Add(tpworkarea);
			}
			StopSession();

			return tpworkareas;

		}


		public IList<iL.Language> ReadLanguages()
		{
			StartSession();			

			GetLanguagesRequest languagesRequest = new GetLanguagesRequest();
			SubscribeRequest(languagesRequest);

			GetLanguagesResponse languages = service.GetLanguages(languagesRequest);
			LogResponse(languages);

			IList<iL.Language> tplanguages = new List<iL.Language>();

			foreach (LWAPI.Language language in languages.Languages)
			{
				iL.Language tplanguage = new iL.Language();
				tplanguage.LanguageId = language.LanguageId.ToString();
				tplanguage.LanguageName = language.LanguageName;

				tplanguages.Add(tplanguage);
			}

			StopSession();

			return tplanguages;
		}
	}
}
